<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title></title>
<jsp:include page="../links.jsp"></jsp:include>
</head>
<body>
	<script type="text/javascript">
		var message_datagrid;
		var message_searchForm;
		var message_addDlg;
		var message_addForm;
		var message_updateDlg;
		var message_updateForm;
		$(function() {
			message_datagrid = $('#message_datagrid').datagrid({
				url : getRootPath() + '/admin/messageAction/datagrid.do',
				title : '留言列表',
				iconCls : 'icon-message',
				pagination : true,
				rownumbers : true,
				selectOnCheck : true,
				checkOnSelect : false,
				pageSize : 10,
				pageList : [ 10, 20, 30, 40, 50 ],
				fit : true,
				fitColumns : true,
				nowarp : false,
				border : false,
				idField : 'mid',
				sortOrder : 'asc',
				columns : [ [ {
					title : '',
					field : 'id',
					width : 100,
					checkbox : true
				}, {
					title : '消息编号',
					field : 'mid',
					width : 50,
					sortable : false
				}, {
					title : '所属商品编号',
					field : 'gid',
					width : 100,
				}, {
					title : '留言人编号',
					field : 'uid',
					width : 100,
				}, {
					title : '留言人姓名',
					field : 'realname',
					width : 100,
				}, {
					title : '回复时间',
					field : 'createtime',
					width : 100
				}, {
					title : '回复内容',
					field : 'content',
					width : 250
				} ] ],
				toolbar : [ {
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						showAddDlg();
					}
				}, '-', {
					text : '删除',
					iconCls : 'icon-remove',
					handler : function() {
						remove();
					}
				} ]
			});//datagrid end
			//过滤查询
			message_searchForm = $('#message_searchForm').form();
			doSearch = function() {
				message_datagrid.datagrid('load', serializeObject(message_searchForm));
			};
			//重置
			cleanSearch = function() {
				message_datagrid.datagrid('load', {});
				message_searchForm.find('input').val('');
			};
			//新增
			message_addDlg = $('#message_addDlg').dialog();
			message_addForm = $('#message_addForm').form();
			showAddDlg = function() {
				$('#message_addForm input').val('');
				message_addDlg.dialog('open')
			};
			doAdd = function() {
				message_addForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/messageAction/add.do?',
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							message_addDlg.dialog('close');
							cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//删除
			remove = function() {
				var selectids = message_datagrid.datagrid('getChecked');
				var ids = [];
				if (selectids.length > 0) {
					$.messager.confirm('确认', '您是否要删除当前选中的项目？', function(r) {
						if (r) {
							for (var i = 0; i < selectids.length; i++) {
								ids.push(selectids[i].mid);
							}
							$.ajax({
								url : '${pageContext.request.contextPath}/admin/messageAction/delete.do',
								data : {
									ids : ids.join(',')
								},
								dataType : 'json',
								success : function(r) {
									message_datagrid.datagrid('load');
									message_datagrid.datagrid('unselectAll');
									$.messager.show({
										title : '提示',
										msg : r.msg
									});
								}
							});
						}
					});
				} else {
					$.messager.alert('提示', "请最少勾选一项");
				}
			};
		});
	</script>
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'north',title:'模糊查询条件：(右边可折叠)'" style="height: 100%;">
			<form id="message_searchForm" method="post">
				<table style="width: 100%; height: 60%;">
					<tr>
						<th class="th-search-label">商品编号:</th>
						<td><input name="message.gid" maxLength=10 class="easyui-numberbox" type="text" /></td>
						<th class="th-search-label">用户编号:</th>
						<td><input name="message.uid" maxLength=10 class="easyui-numberbox" type="text" /></td>
					</tr>
					<tr>
						<th class="th-search-label">用户名字:</th>
						<td><input name="message.realname" /></td>
						<th class="th-search-label">回复内容:</th>
						<td><input name="message.content" /></td>
						<td><a class="easyui-linkbutton" style="width: 25%" data-options="iconCls:'icon-search'"
							href="javascript:void(0)" onclick="doSearch();">查询</a>&nbsp;<a class="easyui-linkbutton"
							style="width: 25%" data-options="iconCls:'icon-redo'" href="javascript:void(0)"
							onclick="cleanSearch();">清空</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',title:''," style="overflow: hidden;">
			<table id="message_datagrid">
			</table>
		</div>
		<div id="message_addDlg"
			data-options="closed:true,modal:true,title:'添加用户',buttons:[
				{text : '添加',iconCls : 'icon-add',handler : function() {doAdd();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {message_addDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 680px; height: 250px;" align="center">
			<form id="message_addForm" method="post">
				<table>
					<tr>
						<th>商品编号:</th>
						<td><input name="message.gid" maxLength=10 class="easyui-validatebox" type="number"
							data-options="required:true,validType:['length[0,10]','number']" /></td>
						<th>用户编号:</th>
						<td><input name="message.uid" maxLength=11 class="easyui-validatebox" type="number"
							data-options="required:true,validType:['length[0,11]','number']" /></td>
					</tr>
					<tr>
						<th>用户姓名:</th>
						<td><input name="message.realname" class="easyui-validatebox" data-options="required:true" /></td>
						<!--<th>创建时间:</th>
						<td><input name="message.createtime" class="easyui-validatebox" data-options="required:true" /></td>  -->
					</tr>
					<tr>
						<th>文章内容:</th>
						<td colspan="3"><textarea name="message.content" class="easyui-validatebox"
								data-options="required:true" style="height: 110px; width: 500px;"></textarea></td>
					<tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>